<?php
class Upload extends CI_Controller {
 
 function __construct()
 {
  parent::__construct();
  $this->load->helper(array('form'));
 
  session_start();
 }
 
 function index()
 { 
 	 $this->load->view('upload_form', array('error' => ' ' ));
  
 	$userid = $_SESSION['qf_userid'];
	if(empty($userid)){
		return ;
	}
 }

 function do_upload(){
 	$userid = $_SESSION['qf_userid'];
	if(empty($userid)){
		return ;
	}
	
  /*$config['upload_path'] = 'upfiles/files/';
  $config['allowed_types'] = 'bmp|gif|jpg|png|zip|rar|doc|xls|txt|pdf|wmv|avi|mp3|mpeg|rm';
  $config['max_size'] = '10240';
  
  $this->load->library('upload', $config);
 
  if (!$this->upload->do_upload()){
	$error = array('error' => $this->upload->display_errors());
	$this->load->view('upload_form', $error);
  } 
else{
   $data = array('upload_data' => $this->upload->data());   
   $this->load->view('upload_success', $data);
  }*/
	
 if ($_FILES["userfile"]["error"] > 0)
  {
  $error = array('error'=> $_FILES["userfile"]["error"]);
  $this->load->view('upload_form', $error);
  }
else
  {
  	$sFileName = str_replace(array(":", "*", "?", "|", "/", "-"), "_", $_FILES["userfile"]["name"]);
  	//$sFileName = str_replace(array("-"), "_", $sFileName);
  	$data['file_name'] = $sFileName;  	
  	
  	if (file_exists("upfiles/files/".$sFileName))
  		$sFileName.='(1)';
  		
  		//转码是因为在windows下
     move_uploaded_file($_FILES["userfile"]["tmp_name"],"upfiles/files/".iconv("UTF-8","gb2312",$sFileName));
      	$this->load->view('upload_success', $data);
    }
  	
  /*echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  */
 }
}
?>